package lyo.levelup.rating;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class TestSystem {
   private static final int NUMBER_ELEMENT_ON_PAGE = 5;
   private TreeMap <Player, String> tm = new TreeMap <Player, String> ();
   private TreeMap <String, Integer> searchByRating = new TreeMap <String, Integer> ();
   private ArrayList <String> listUsers = new ArrayList <String> ();
   private ArrayList <String> systemUsers = new ArrayList <String> ();
   private String str = "";
   private Map.Entry tmp;
   private byte count = 0;
   /*
    public List<Player> getPage(int pageNum)
    {
        List<Player> toSend = new ArrayList<Player>();
        Set<Player> allSet = tm.keySet();
        List<Player> allList = new ArrayList<Player>(tm.keySet());
        int from = pageNum * 5;
        int to = (pageNum + 1)*5;
        allList.listIterator(from);
        return toSend;
    }
    */
   public void addPlayerToSystem(Player p)
    {
        tm.put(p, p.getName());
        searchByRating.put(p.getName(), p.getPlayerRating());
    }
   public List <String> topFiveUsers()
   {
      Iterator <Map.Entry<Player,String>> iter;
      iter = tm.entrySet().iterator();
      while(iter.hasNext())
        {
            tmp = iter.next();
            if(count < NUMBER_ELEMENT_ON_PAGE)
            {
             listUsers.add(tmp.getValue().toString());
            }
            count++;
        }  
      return listUsers;
   }
  public ArrayList <String> showSystem()
    {
        Iterator<Map.Entry<Player,String>> iter = tm.entrySet().iterator();
        while (iter.hasNext())
        {
            tmp = iter.next();
            systemUsers.add((tmp.getKey() + ":" + tmp.getValue()));
        }
        return systemUsers;
    }
   public String showUserRating(String userName)
   {
      Iterator <Map.Entry<String, Integer>> iter;
      iter = searchByRating.entrySet().iterator();
      while(iter.hasNext())
      {
          tmp=iter.next();
          if(tmp.getKey().equals(userName))
          {
              str += tmp.getValue();
          }
      }
       return str;
   }
}